<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head >
	<th:block th:include="include :: header" />
	<th:block th:include="include :: datetimepicker-css" />
	<th:block th:include="include :: bootstrap-fileinput-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-contractInfo-edit" th:object="${contractInfo}">
            <input id="contractId" name="contractId" th:field="*{contractId}"  type="hidden">
			<div class="form-group">	
				<label class="col-sm-3 control-label">合同编号：</label>
				<div class="col-sm-8">
					<input id="contractNum" name="contractNum" th:field="*{contractNum}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">合同名称：</label>
				<div class="col-sm-8">
					<input id="contractName" name="contractName" th:field="*{contractName}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">签订地点：</label>
				<div class="col-sm-8">
					<input id="signPlace" name="signPlace" th:field="*{signPlace}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">签订单位：</label>
				<div class="col-sm-8">
					<input id="signUnit" name="signUnit" th:field="*{signUnit}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">合同负责人：</label>
				<div class="col-sm-8">
					<input id="contractPrincipal" name="contractPrincipal" th:field="*{contractPrincipal}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">联系方式：</label>
				<div class="col-sm-8">
					<input id="linkWay" name="linkWay" th:field="*{linkWay}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">签订日期：</label>
				<div class="col-sm-8">
					<div class="input-group date">
						<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
						<input id="signDate" name="signDate" th:field="*{signDate}" type="text" class="form-control" placeholder="yyyy-MM-dd" required>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">到期日期：</label>
				<div class="col-sm-8">
					<div class="input-group date">
						<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
						<input id="maturityDate" name="maturityDate" th:field="*{maturityDate}" type="text" class="form-control" placeholder="yyyy-MM-dd" required>
					</div>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">合同金额：</label>
				<div class="col-sm-8">
					<input id="contractAmount" name="contractAmount" th:field="*{contractAmount}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">合同上传：</label>
				<div class="col-sm-8">
					<input name="contractAttachment" id="contractAttachment" th:field="*{contractAttachment}" class="form-control" type="hidden"/>
					<div class="file-loading">
						<input id="fileinput-upload" type="file" multiple name="file">
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label"></label>
				<div class="col-sm-8">
					<div th:each="attach : ${attachmentList}" style="display: flex">
						<a th:href="${attach.attachUrl}" th:text="${attach.attachTitle}"></a>&nbsp;&nbsp;<a th:data-id="${attach.attachId}" class="delResources" style="font-size: 3px;color: red;">删除</a>
					</div>
					<input name="contractAttachment" th:field="*{contractAttachment}" class="form-control" type="hidden"  disabled="disabled">
				</div>
			</div>
		</form>
    </div>
	<th:block th:include="include :: footer" />
	<th:block th:include="include :: datetimepicker-js" />
	<th:block th:include="include :: bootstrap-fileinput-js" />
    <script type="text/javascript">
		var prefix = ctx + "business/contractInfo";
		$("#form-contractInfo-edit").validate({
			rules:{
				xxxx:{
					required:true,
				},
			}
		});

		$(function () {
			//bootstrap-fileinput
			$("#fileinput-upload").fileinput({
				language: 'zh',
				'theme': 'explorer-fas',
				'uploadUrl': ctx + 'business/attachment/uploadMore',
				uploadAsync:false,//false 同步上传，后台用数组接收，true 异步上传，每次上传一个file,会调用多次接口
				overwriteInitial: false,
				initialPreviewAsData: true,
				allowedFileExtensions : ['doc','docx','pdf','PDF',"xls", "xlsx","exe","bmp", "gif", "jpg", "jpeg", "png",
					"ppt", "pptx", "html", "htm", "txt","rar", "zip", "mp3","mp4","MPEG","MP3\MPEG-4","MIDI","WMA"],//接收的文件后缀
				showPreview: true,
				showUpload: true, //是否显示上传按钮
				showCaption: true,//是否显示标题
				maxFileCount: 5, //表示允许同时上传的最大文件个数
				maxFileSize: 200000
			}).on("filebatchuploadsuccess", function(event, data) {
				$("#contractAttachment").val(data.response.url);
			});

			/* 日期控件 */
			layui.use('laydate', function() {
				var laydate = layui.laydate;
				laydate.render({
					elem: '#signDate',
					type: 'date'
				});
				laydate.render({
					elem: '#maturityDate',
					type: 'date'
				});
			});
		});


		//删除附件
		$(".delResources").click(function(){
			var attachId = $(this).attr("data-id");//获得参数的值
			$.modal.confirm("确定删除该资源吗？",function(s){
				$.ajax({
					type:'post',
					url: ctx + "business/attachment/remove",
					data:{ids:attachId},
					success:function (result) {
						var url = ctx + "business/contractInfo/edit/"+$("#contractId").val();
						console.log(url);

						//刷新当前tab
						var currentId = $('.page-tabs-content',parent.document).find('.active').attr('data-id');
						var target = $('.RuoYi_iframe[data-id="' + currentId + '"]',parent.document);
						var url = target.attr('src');
						target.attr('src', url).ready();
					}
				});
			});
		});

		function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save(prefix + "/edit", $('#form-contractInfo-edit').serialize());
	        }
	    }
	</script>
</body>
</html>
